/*
 * Project:     My Project Work, Copyright (C) 2011
 * Created at:  03.08.2011
 */
package de.myprojectwork.view;

import de.myprojectwork.common.util.Logger;
import de.myprojectwork.presenter.AbstractPresenter;
import de.myprojectwork.presenter.Presenter;
import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Chris Holdschuh
 */
public abstract class AbstractView<T> extends JPanel implements View {
    
    protected T presenter;
    
    public AbstractView(T presenter) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException ex) {
            Logger.error("Look and Feel kann nicht gesetzt werden", ex);
        }
        this.presenter = presenter;
    }

    public Presenter getPresenter() {
        return (Presenter) presenter;
    }
    
    protected void addComponent(Container cont, GridBagLayout gbl, Component c, 
            int x, int y, int width, int height, double weightx, double weighty, int fill,
            int anchor, Insets insets, int ipadx, int ipady) {
        
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = fill;
        gbc.gridx = x; 
        gbc.gridy = y;
        gbc.gridwidth = width; 
        gbc.gridheight = height;
        gbc.weightx = weightx; 
        gbc.weighty = weighty;
        gbc.anchor = anchor;
        gbc.ipadx = ipadx;
        gbc.ipady = ipady;
        if (insets != null) {
            gbc.insets = insets;
        }
        gbl.setConstraints(c,gbc);
        cont.add(c);
    }
    
    protected void add(Container cont, GridBagLayout gbl, Component c, 
            int x, int y, int width, int height, double weightx, double weighty, int fill,
            int anchor, Insets insets) {
        
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = fill;
        gbc.gridx = x; 
        gbc.gridy = y;
        gbc.gridwidth = width; 
        gbc.gridheight = height;
        gbc.weightx = weightx; 
        gbc.weighty = weighty;
        gbc.anchor = anchor;
        if (insets != null) {
            gbc.insets = insets;
        }
        gbl.setConstraints(c,gbc);
        cont.add(c);
    }
    
    protected void add(Container cont, GridBagLayout gbl, Component c, 
            int x, int y, int width, int height, double weightx, double weighty, int fill,
            int anchor) {
        
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = fill;
        gbc.gridx = x; 
        gbc.gridy = y;
        gbc.gridwidth = width; 
        gbc.gridheight = height;
        gbc.weightx = weightx; 
        gbc.weighty = weighty;
        gbc.anchor = anchor;
        gbl.setConstraints(c,gbc);
        cont.add(c);
    }
    
    protected void add(Container cont, GridBagLayout gbl, Component c, 
            int x, int y, int width, int height) {
        
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = x; 
        gbc.gridy = y;
        gbc.gridwidth = width; 
        gbc.gridheight = height;
        gbl.setConstraints(c,gbc);
        cont.add(c);
    }
}
